# import panda main module
import direct.directbase.DirectStart

from pandac.PandaModules import *

# set the ambient light
class Lights:
    def __init__(self, parent):
        # 12 minute = 720 seconds = 1 day in the game
        self.daySeconds = 720
        self.days = 0
        self.hour = self.daySeconds / 24.0
        
        # set the sunlight
        self.sun = DirectionalLight('sun')
        self.sun_node = render.attachNewNode(self.sun)
        self.sun_node.setHpr(-30, -60, 0)
        render.setLight(self.sun_node)
        
        alight = AmbientLight('alight')
        alight.setColor(VBase4(1, 1, 1, 1))
        alnp = render.attachNewNode(alight)
        # only the skydrome must be illuminated
        parent.map.skydrome.setLight(alnp)
        
        #taskMgr.add(self.meteo, "meteo")
    
    # method that manages the sun movement
    def meteo(self, task):
        day_second = task.time - (self.days*self.daySeconds)
        # if the day is finished
        if day_second > self.daySeconds:
            self.days += 1
        
        # if is day
        if day_second < self.daySeconds*0.6:
            day_hour = day_second / self.hour
            self.sun_node.setHpr(day_hour*15, -60, 0)
        
        return task.cont
